package cn.edu.nju.software.cdiy.algorithm.performance;

import cn.edu.nju.software.cdiy.bean.Disk;
import cn.edu.nju.software.cdiy.util.Constant;

public class DiskEvaluator implements Evaluator<Disk>{

	@Override
	public double getPerformance(Disk d) {
		double score = 0;
		//单碟容量得分
		String singleCapacity = d.getSingleCapacity().getValue();
		double singleCapacityScore = getSingleCapicityBase(singleCapacity)*Constant.DISK_STD_SINGLECAPACITY;
		
		//转速得分
		String rotateSpeed = d.getRotateSpeed().getValue();
		double rotateSpeedScore = getRotateSpeedBase(rotateSpeed)*Constant.DISK_STD_ROTATESPEED;
		
		//缓存容量得分
		String cacheSize = d.getCacheSize().getValue();
		double cacheSizeScore = getCacheSizeBase(cacheSize)*Constant.DISK_STD_CACHESIZE;
		
		//接口标准得分
		String intfStd = d.getIntfStd().getName();
		double intfStdScore = getIntfStdBase(intfStd)*Constant.DISK_STD_INTFSTD;
		
		
		score = singleCapacityScore+rotateSpeedScore+cacheSizeScore+intfStdScore;
		return score;
	}

	private double getIntfStdBase(String intfStd) {
		/*
		 * 接口标准基础分
		 * PATA			60
		 * SATA1.0		70
		 * SATA2.0		80
		 * SATA3.0		85
		 * SAS			90
		 * */
		if(intfStd.equals("PATA"))
			return 60;
		if(intfStd.equals("SATA1.0"))
			return 70;
		if(intfStd.equals("PATA2.0"))
			return 80;
		if(intfStd.equals("PATA3.0"))
			return 85;
		if(intfStd.equals("SAS"))
			return 90;
		else return 95;
	}

	private double getCacheSizeBase(String cacheSize) {
		/*
		 * 缓存容量基础分
		 * 8M			60
		 * 16M			70
		 * 32M			80
		 * 64M			90
		 * */
		if(cacheSize.equals("8M"))
			return 60;
		else if(cacheSize.equals("16M"))
			return 70;
		else if(cacheSize.equals("32M"))
			return 80;
		else if(cacheSize.equals("64M"))
			return 90;
		else return 95;
	}

	private double getRotateSpeedBase(String rotateSpeed) {
		/*
		 * 转速基础分
		 * 5400			50	
		 * 5900			60
		 * 7200			70
		 * 10000		80
		 * 15000		90
		 * */
		if(rotateSpeed.equals("5400转"))
			return 50;
		else if(rotateSpeed.equals("5900转"))
			return 60;
		else if(rotateSpeed.equals("7200转"))
			return 70;
		else if(rotateSpeed.equals("10000转"))
			return 80;
		else if(rotateSpeed.equals("15000转"))
			return 90;
		else return 95;
	}

	private double getSingleCapicityBase(String singleCapacity) {
		/*
		 * 单碟容量基础分
		 * 80GB			40
		 * 160GB		60
		 * 250GB		65
		 * 320GB		70	
		 * 500GB		80	
		 * 600GB		90	
		 * 1TB			95
		 * */
		if(singleCapacity.equals("80GB"))
			return 40;
		else if(singleCapacity.equals("160GB"))
			return 60;
		else if(singleCapacity.equals("250GB"))
			return 65;
		else if(singleCapacity.equals("320GB"))
			return 70;
		else if(singleCapacity.equals("500GB"))
			return 80;
		else if(singleCapacity.equals("600GB"))
			return 90;
		else if(singleCapacity.equals("1TB"))
			return 95;
		else return 100;
	}

}
